from django.core.exceptions import SuspiciousOperation


class SuspiciousOpinion(SuspiciousOperation):
    """
    The user tried to respond to a questionnaire in a suspicious way
    """
    message_fmt = "The user '%s' attempted to respond to the questionnaire '%s' in a suspicious way"
    
    def __init__(self, user, questionnaire):
        self.user = user
        self.questionnaire = questionnaire
        self.message = self.message_fmt % (self.user, self.questionnaire)

    def __str__(self):
        return self.message


class RespondingToNonLiveQuestionnaire(SuspiciousOpinion):
    """
    The user tried to respond to non-Live questionnaire
    """
    message_fmt = "The user '%s' attempted to respond to the questionnaire '%s' whose status is not `Live`"


class TooManyAnswers(SuspiciousOpinion):
    """
    The user tried to respond to questionnaire with too many answers
    """
    message_fmt = "The user '%s' attempted to respond to the questionnaire '%s' with too many answers"


class TooFewAnswers(SuspiciousOpinion):
    """
    The user tried to respond to questionnaire with too few answers
    """
    message_fmt = "The user '%s' attempted to respond to the questionnaire '%s' with too few answers"


class InvalidAnswer(SuspiciousOpinion):
    """
    The user tried to respond to a questionnaires question with an invalid answer
    """
    message_fmt = "The user '%s' attempted to respond to the questionnaires '%s' question #%d with an invalid answer"
    
    def __init__(self, user, questionnaire, question):
        self.user = user
        self.questionnaire = questionnaire
        self.question = question
        self.message = self.message_fmt % (self.user, self.questionnaire, self.question)


class UserNotInPopulation(SuspiciousOpinion):
    """
    The user is not a part of questionnaires population
    """
    message_fmt = "The user '%s' is not a part of questionnaires '%s' population"


class UserTinkeredWithOpinionForm(SuspiciousOpinion):
    """
    The user tried to tinker with opinion change form
    """
    message_fmt = "The user '%s' attempted to tinker with opinion change form for the questionnaires '%s'"


class OpinionFormTimedOut(SuspiciousOpinion):
    """
    The user timed out the opinion change form
    """
    message_fmt = "The user '%s' attempted to respond to the questionnaires '%s' when the opinion change form timed out"
